package org.gorson.utils.es;

import org.apache.http.HttpHost;
import org.gorson.utils.CastUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

/**
 * ES 配置类
 * 注意：在flink中使用，需要序列化
 */
public class ESProperties implements Serializable {
    private String hostName;
    private int port; // 使用的端口号
    private String schema = "http"; // 使用的协议
    private ArrayList<HttpHost> hostList = null;

    private int connectTimeOut; // 连接超时时间
    private int connectionRequestTimeOut; // 获取连接的超时时间
    private int maxConnectNum; // 最大连接数

    private int socketTimeOut; // 连接超时时间
    private int maxConnectPerRoute; // 最大路由连接数

    public ESProperties(Map properties) {
/*
        todo  config with apollo
        this.hostName = properties.get(ApolloConfig4ESEnum.elasticsearch_hostName.code()).toString();
        this.port = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_port.code()), 9200);
        this.connectTimeOut = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_connectTimeOut.code()), 1000);
        this.connectionRequestTimeOut = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_connectionRequestTimeOut.code()), 500);
        this.maxConnectNum = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_maxConnectNum.code()), 10);
        this.socketTimeOut = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_socketTimeOut.code()), 30000);
        this.maxConnectPerRoute = CastUtil.castInt(properties.get(ApolloConfig4ESEnum.elasticsearch_maxConnectPerRoute.code()), 30000);
*/

        this.hostName = "127.0.0.1";
        this.port = CastUtil.castInt(9200, 9200);
        this.connectTimeOut = CastUtil.castInt(1000, 1000);
        this.connectionRequestTimeOut = CastUtil.castInt(500, 500);
        this.maxConnectNum = CastUtil.castInt(10, 10);
        this.socketTimeOut = CastUtil.castInt(30000, 30000);
        this.maxConnectPerRoute = CastUtil.castInt(30000, 30000);


    }

    public String getHostName() {
        return hostName;
    }

    public int getPort() {
        return port;
    }

    public String getSchema() {
        return schema;
    }

    public ArrayList<HttpHost> getHostList() {
        return hostList;
    }

    public int getConnectTimeOut() {
        return connectTimeOut;
    }

    public int getSocketTimeOut() {
        return socketTimeOut;
    }

    public int getConnectionRequestTimeOut() {
        return connectionRequestTimeOut;
    }

    public int getMaxConnectNum() {
        return maxConnectNum;
    }

    public int getMaxConnectPerRoute() {
        return maxConnectPerRoute;
    }
}
